package normalapi;

import java.util.ArrayList;

public class MathDemo {
    public static void main(String[] args) {
        // 1. Math.abs() 绝对值，Math.absExact()超出范围会报错44
        System.out.println(Math.abs(-10)); // 10
        // 2. Math.ceil() 向上取整
        System.out.println(Math.ceil(10.1)); // 11.0
        // 3. Math.floor() 向下取整
        System.out.println(Math.floor(10.9)); // 10.0
        // 4. Math.round() 四舍五入
        System.out.println(Math.round(10.5)); // 11
        // 5. Math.pow() 求幂
        System.out.println(Math.pow(2, 3)); // 8.0
        // 6. Math.sqrt() 求平方根
        System.out.println(Math.sqrt(9)); // 3.0
        // 7. 求立方根
        System.out.println(Math.cbrt(8)); //2.0

        ArrayList<Integer> list = isZiMi();
        for (Integer integer : list) {
            System.out.println(integer);
        }
    }

    private static ArrayList<Integer> isZiMi() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int num = 100; num <=999 ; num++) {
            int bai = num/100 % 10;
            int shi = num / 10 %10;
            int ge = num%10;
            if (Math.pow(ge,3)+Math.pow(shi,3)+Math.pow(bai,3) == num){
                list.add(num);
            }
        }
        return list;
    }

}
